home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1992 August / info-mac-1992.iso / Source / 3D GrafSys / GrafSys.rel / Demo Sources / squaredance.p < prev    next >
Text File  |  1992-04-25  |  3KB  |  119 lines

  1. program TestGrafSys;
  2.  
  3. { 3d GrafSys Demo Program}
  4. { Vers. 1.1 }
  5. { (c) 1992 by Christian Franz }
  6.  
  7. { This program demonstates the use of the grafsys for simple animation using }
  8. { the fDrawObject and free rotation command                                                 }
  9. { It also demonstrates the use of AddPoint and AddLine routines for building    }
  10. { 3D objects                                                                                                   }
  11.  
  12.     uses
  13.         Grafsys, Screen3D;
  14.  
  15.     const
  16.         theWindowID = 400;
  17.         degree = 0.01745329; (* π/180 *)
  18.  
  19.     var
  20.         theWindow: WindowPtr;
  21.         theInt: INTEGER;
  22.         thePort: Graf3DPtr;
  23.         theMaster: Graf3DPtr;
  24.         Pyramid, Cube, xFighter: GrafObjPtr;
  25.         theEvent: EventRecord;
  26.         dx, dy, dz: integer;
  27.         r: Rect;
  28.         p1, p2: Vector4;
  29.         sign: integer;
  30.  
  31.     procedure makesquare (var Obj: GrafObjPtr);
  32.  
  33.         var
  34.             OK: Boolean;
  35.             c: INTEGER;
  36.  
  37.     begin
  38.         Obj := NewObject;
  39.         OK := AddPoint(Obj, 100, 100, 0, c);
  40.         OK := AddPoint(Obj, -100, 100, 0, c);
  41.         OK := AddPoint(Obj, -100, -100, 0, c);
  42.         OK := AddPoint(Obj, 100, -100, 0, c);
  43.  
  44.         OK := AddLine(Obj, 1, 2);
  45.         OK := AddLine(Obj, 2, 3);
  46.         OK := AddLine(Obj, 3, 4);
  47.         OK := AddLine(Obj, 4, 1);
  48.     end;
  49.  
  50.  
  51.     procedure getmouserot (var dx, dy, dz: integer);
  52.  
  53.         var
  54.             thePoint: point;
  55.  
  56.     begin
  57.         GetMouse(thePoint);
  58.         dx := 0;
  59.         dy := 0;
  60.         dz := 0;
  61.         if (thePoint.h < thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 1 -> xrot*)
  62.             begin
  63.                 dx := 5;
  64.             end;
  65.         if (thePoint.h > thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 2 -> yrot*)
  66.             begin
  67.                 dy := 5;
  68.             end;
  69.         if (thePoint.h > thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 3 -> zrot*)
  70.             begin
  71.                 dz := 5;
  72.             end;
  73.         if (thePoint.h < thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 4 -> idle*)
  74.             begin
  75.             end;
  76.         if button then
  77.             begin
  78.                 dx := -dx;
  79.                 dy := -dy;
  80.                 dz := -dz;
  81.             end;
  82.     end;
  83.  
  84.  
  85. begin
  86.     theWindow := GetNewWindow(theWindowID, nil, Pointer(-1));
  87.     SetPort(theWindow); (* draw in this window *)
  88.  
  89. {PenMode(patXOR);}
  90.     MoveTo(10, 10);
  91.     DrawString('3D Grafiksystem.             Object: Square.         (C) 1991 by C Franz.');
  92.     InitGrafSys;
  93.     NewGrafport(theWindow^.portRect, thePort);
  94.     MoveTo(10, thePort^.bottom - 0);
  95.     DrawString(' Press Button to Exit');
  96.     MakeSquare(cube);
  97.     SetEye(False, 0, 0, 0, 0, 0, 0, 1.512, FALSE);
  98.     ObjFreeTranslate(cube, 0, 0, 500);
  99.     ObjRotate(cube, 0 * degree, 0 * degree, 0);
  100.     ObjScale(cube, 1, 1, 1);
  101.     SetAutoErase(cube, True);
  102.     p1[1] := 0;
  103.     p1[2] := 0;
  104.     p1[3] := 400;
  105.  
  106.     p2[1] := 0;
  107.     p2[2] := 200;
  108.     p2[3] := 400;
  109.  
  110.     p1[4] := 1;
  111.     p2[4] := 1;
  112.     sign := 1;
  113.     fDrawObject(cube);
  114.     repeat
  115.         fDrawObject(cube);
  116.         ObjRotateArb(cube, p1, p2, 2 * degree); (* although locally done has global effect *)
  117.         ObjRotate(cube, 0, -8 * degree, 0);
  118.     until Button;
  119. end.